/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class ComunaDAOImpl implements orm.dao.ComunaDAO {
	private static final org.apache.log4j.Logger _logger = org.apache.log4j.Logger.getLogger(ComunaDAOImpl.class);
	public Comuna loadComunaByORMID(int co_id) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadComunaByORMID(session, co_id);
		}
		catch (Exception e) {
			_logger.error("loadComunaByORMID(int co_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna getComunaByORMID(int co_id) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return getComunaByORMID(session, co_id);
		}
		catch (Exception e) {
			_logger.error("getComunaByORMID(int co_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByORMID(int co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadComunaByORMID(session, co_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadComunaByORMID(int co_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna getComunaByORMID(int co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return getComunaByORMID(session, co_id, lockMode);
		}
		catch (Exception e) {
			_logger.error("getComunaByORMID(int co_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByORMID(PersistentSession session, int co_id) throws PersistentException {
		try {
			return (Comuna) session.load(orm.Comuna.class, new Integer(co_id));
		}
		catch (Exception e) {
			_logger.error("loadComunaByORMID(PersistentSession session, int co_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna getComunaByORMID(PersistentSession session, int co_id) throws PersistentException {
		try {
			return (Comuna) session.get(orm.Comuna.class, new Integer(co_id));
		}
		catch (Exception e) {
			_logger.error("getComunaByORMID(PersistentSession session, int co_id)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByORMID(PersistentSession session, int co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Comuna) session.load(orm.Comuna.class, new Integer(co_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("loadComunaByORMID(PersistentSession session, int co_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna getComunaByORMID(PersistentSession session, int co_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Comuna) session.get(orm.Comuna.class, new Integer(co_id), lockMode);
		}
		catch (Exception e) {
			_logger.error("getComunaByORMID(PersistentSession session, int co_id, org.hibernate.LockMode lockMode)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna[] listComunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return listComunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("listComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna[] listComunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return listComunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("listComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna[] listComunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Comuna as Comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Comuna[]) list.toArray(new Comuna[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listComunaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna[] listComunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Comuna as Comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Comuna[]) list.toArray(new Comuna[list.size()]);
		}
		catch (Exception e) {
			_logger.error("listComunaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadComunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("loadComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return loadComunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("loadComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Comuna[] comunas = listComunaByQuery(session, condition, orderBy);
		if (comunas != null && comunas.length > 0)
			return comunas[0];
		else
			return null;
	}
	
	public Comuna loadComunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Comuna[] comunas = listComunaByQuery(session, condition, orderBy, lockMode);
		if (comunas != null && comunas.length > 0)
			return comunas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateComunaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return iterateComunaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			_logger.error("iterateComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateComunaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.EvaluacionDocentePersistentManager.instance().getSession();
			return iterateComunaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			_logger.error("iterateComunaByQuery(String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateComunaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Comuna as Comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateComunaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateComunaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Comuna as Comuna");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			_logger.error("iterateComunaByQuery(PersistentSession session, String condition, String orderBy)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna createComuna() {
		return new orm.Comuna();
	}
	
	public boolean save(orm.Comuna comuna) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().saveObject(comuna);
			return true;
		}
		catch (Exception e) {
			_logger.error("save(orm.Comuna comuna)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Comuna comuna) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().deleteObject(comuna);
			return true;
		}
		catch (Exception e) {
			_logger.error("delete(orm.Comuna comuna)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Comuna comuna)throws PersistentException {
		try {
			if(comuna.getRegionre_numeroregion() != null) {
				comuna.getRegionre_numeroregion().comuna.remove(comuna);
			}
			
			return delete(comuna);
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Comuna comuna, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(comuna.getRegionre_numeroregion() != null) {
				comuna.getRegionre_numeroregion().comuna.remove(comuna);
			}
			
			try {
				session.delete(comuna);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			_logger.error("deleteAndDissociate()", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Comuna comuna) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().getSession().refresh(comuna);
			return true;
		}
		catch (Exception e) {
			_logger.error("refresh(orm.Comuna comuna)", e);
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Comuna comuna) throws PersistentException {
		try {
			orm.EvaluacionDocentePersistentManager.instance().getSession().evict(comuna);
			return true;
		}
		catch (Exception e) {
			_logger.error("evict(orm.Comuna comuna)", e);
			throw new PersistentException(e);
		}
	}
	
	public Comuna loadComunaByCriteria(ComunaCriteria comunaCriteria) {
		Comuna[] comunas = listComunaByCriteria(comunaCriteria);
		if(comunas == null || comunas.length == 0) {
			return null;
		}
		return comunas[0];
	}
	
	public Comuna[] listComunaByCriteria(ComunaCriteria comunaCriteria) {
		return comunaCriteria.listComuna();
	}
}
